package org.dzms.dao;

import java.util.List;

import org.dzms.commons.DataHandler;
import org.dzms.commons.IPage;
import org.dzms.commons.PageHandler;
import org.dzms.entity.HomePage;

public class homePageDAO implements IPage{
	/**
	 * ========================================================
	 * 												首页信息查询
	 * ========================================================
	 */
	//查询所有首页信息
	public List<HomePage> findAllHp() {
		String sql = "select *from homepage";
		return DataHandler.query(sql, null, HomePage.class);
	}
	//保存首页信息
	public void saveHp(HomePage hp) {
		String sql = "insert into homepage(hppic, hpshname, hpcommens,"
						+ " hpavgpri, hpclass, hpaddress) values(?,?,?,?,?,?)";
		DataHandler.update(sql, new Object[]{hp.getHppic(), hp.getHpshname(), 
																		 hp.getHpcommens(), hp.getHpavgpri(), 
																		 hp.getHpclass(), hp.getHpaddress()});
	}
	//删除首页信息
	public void deleteHp(int hpid) {
		String sql = "delete from homepage where userid=?";
		DataHandler.update(sql, new Object[]{hpid});
	}
	//更新首页信息
	public void updateHp(HomePage hp) {
		String sql = "update hpmepage set hppic=?, hpshname=?, hpcommens=?, hpavgpri=?, hpclass=?, hpaddress=? where hpid=?";
		DataHandler.update(sql, new Object[]{hp.getHppic(), hp.getHpshname(), 
				 														 hp.getHpcommens(), hp.getHpavgpri(), 
				 														 hp.getHpclass(), hp.getHpaddress(), hp.getHpid()});
	}
	
	public <E> List<E> findCurrentPageData(PageHandler handler) {
		String sql = "select * from homepage limit ?,?";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return DataHandler.query(sql, new Object[]{(handler.getCurrentPage()-1)*handler.getPageSize(),handler.getPageSize()},HomePage.class);
	}

	public int findCountPage(PageHandler handler) {
		String sql = "select ceil(count(*)/?) from homepage";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return Integer.parseInt(DataHandler.uniqueQuery(sql, new Object[]{handler.getPageSize()}).toString());
	}
	public <E> List<E> findCurrentPageDatadesc(PageHandler handler) {
		// TODO Auto-generated method stub
		return null;
	}
	public <E> List<E> foods(String a, PageHandler handler) {
		// TODO Auto-generated method stub
		return null;
	}
}
